package cn.hfatec.shms.web.xc.xcMplan.action;

import cn.hfatec.shms.web.xh.xhBkj.model.XhBkjParams;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import javax.annotation.Resource;


import cn.hfatec.JsonResponse;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.constants.SysContant;
import cn.hfatec.freemarker.FreeMarkerUtil;
import cn.hfatec.shms.web.xc.xcMplan.model.XcMplanParams;
import cn.hfatec.shms.web.xc.xcMplan.model.XcMplan;
import cn.hfatec.shms.web.xc.xcMplan.service.XcMplanService;
import cn.hfatec.shms.base.ShmsBaseAction;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;



/**
 *
 * @author hfatec codegen
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Controller
@RequestMapping("/xc/xcMplan")
public class XcMplanAction extends ShmsBaseAction {

    //服务层
    @Resource(name = "XcMplanService")
    private XcMplanService xcMplanService;


    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/list")
    public String list(XcMplanParams xcMplanParams, Page page, Model model) {

        Table table = xcMplanService.queryXcMplanTable(xcMplanParams, page);
       List list=xcMplanService.getXcMplanList(xcMplanParams);
        model.addAttribute("xcMplansTable", table);
        model.addAttribute("xcMplansList", list);
       model.addAttribute("xcMplanParams", xcMplanParams);
        return "/xc/xcMplan/list";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/ajaxList")
    @ResponseBody
    public String ajaxList(XcMplanParams xcMplanParams, Page page, Model model) {
        try {
            list(xcMplanParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/xc/xcMplan/table", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }

    /**
     * 导出excel
     */
    @RequestMapping("/export")
    @ResponseBody
    public String export(XcMplanParams xcMplanParams, HttpServletRequest request, HttpServletResponse response) {
        try {
            xcMplanService.exportExcel(xcMplanParams, request, response);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }
}
